﻿using CommunityToolkit.Mvvm.ComponentModel;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using XYAC.Framework.MonitorTireMaterialManual.DataExporter;
using XYAC.Framework.MonitorTireMaterialManual.OracleRemoteDB;

namespace XYAC.Framework.MonitorTireMaterialManual.Entities
{
    /// <summary>
    /// 胎面报表数据
    /// </summary>
    public partial class SemiSteelTreadScanReport : ReportEntityBase
    {

        public SemiSteelTreadScanReport()
        {
            LastSyncDate = DateTime.Now;
        }

        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public override int ID { get; set; }
        //public string? UserId { get; set; }
        /// <summary>
        /// 补偿系数
        /// </summary>
        [Description("补偿系数")]
        [ObservableProperty]
        private double?  _compensationCoefficient=0.0;

        /// <summary>
        /// 规格号
        /// </summary>
        [Description("规格号")]
        [ObservableProperty]
        private string? _specName;

        /// <summary>
        /// 实际规格号
        /// </summary>
        [Description("实际规格号")]
        [ObservableProperty]
        private string? _specNameInfact;

        [ObservableProperty]
        private string? _serialNumber;
        [ObservableProperty]
        private string? _scanedDatetime;

        /// <summary>
        /// 总面积=左设定面积+右设定面积
        /// </summary>
        [ObservableProperty]
        private double? _totalArea=0.0;
        [ObservableProperty]
        private double? _totalLeftArea=0.0;
        [ObservableProperty]
        private double? _totalRightArea = 0.0;
        [ObservableProperty]
        private double? _measureArea =0.0;
        [ObservableProperty]
        private double? _measureLeftArea = 0.0;
        [ObservableProperty]
        private double? _measureRightArea = 0.0;
        /// <summary>
        /// 总宽标准
        /// </summary>
        [ObservableProperty]
        private double? _totalWidth_Stable = 0.0;

        /// <summary>
        /// 总宽扫描
        /// </summary>
        [ObservableProperty]
        private double? _totalWidth_Scan = 0.0;

        /// <summary>
        /// 冠宽对称性
        /// </summary>
        [ObservableProperty]
        private double? _totalWidth_Symmetry = 0.0;
        /// <summary>
        /// 冠宽标准
        /// </summary>
        [ObservableProperty]
        private double? _crownWidth_Stable = 0.0;

        /// <summary>
        /// 冠宽扫描
        /// </summary>
        [ObservableProperty]
        private double? _crownWidth_Scan = 0.0;

        /// <summary>
        /// 冠宽对称性
        /// </summary>
        [ObservableProperty]
        private double? _crownWidth_Symmetry = 0.0;
        /// <summary>
        /// 肩厚标准
        /// </summary>
        [ObservableProperty]
        private double? _shoulderThickness_Stable = 0.0;
        /// <summary>
        /// 肩厚扫描左
        /// </summary>
        [ObservableProperty]
        private double? _shoulderThickness_ScanLeft = 0.0;
        /// <summary>
        /// 肩厚扫描右
        /// </summary>
        [ObservableProperty]
        private double? _shoulderThickness_ScanRight = 0.0;
        /// <summary>
        /// 肩厚对称性
        /// </summary>
        [ObservableProperty]
        private double? _shoulderThickness_Symmetry = 0.0;
        /// <summary>
        /// 冠宽标准
        /// </summary>
        [ObservableProperty]
        private double? _crownThickness_Stable = 0.0;

        /// <summary>
        /// 冠宽扫描
        /// </summary>
        [ObservableProperty]
        private double? _crownThickness_Scan = 0.0;

        /// <summary>
        /// 其他点厚度标准
        /// </summary>
        [ObservableProperty]
        private string? _othoerPointsThickness_Stable;
        /// <summary>
        /// 其他点厚度扫描
        /// </summary>
        [ObservableProperty]
        private string? _othoerPointsThickness_Scan;
        /// <summary>
        /// 胎翼端点厚度扫描左
        /// </summary>
        [ObservableProperty]
        private double? _beadWingTipThickness_ScanLeft = 0.0;
        /// <summary>
        /// 胎翼端点厚度扫描右
        /// </summary>
        [ObservableProperty]
        private double? _beadWingTipThickness_ScanRight = 0.0;
        /// <summary>
        /// 胎翼宽度标准
        /// </summary>
        [ObservableProperty]
        private double? _beadWingWidth_Stable = 0.0;
        /// <summary>
        /// 胎翼宽度扫描左
        /// </summary>
        [ObservableProperty]
        private double? _beadWingWidth_ScanLeft = 0.0;
        /// <summary>
        /// 胎翼宽度扫描右
        /// </summary>
        [ObservableProperty]
        private double? _beadWingWidth_ScanRight = 0.0;
        /// <summary>
        /// 胎翼宽度对称性
        /// </summary>
        [ObservableProperty]
        private double? _beadWingWidth_Symmetry = 0.0;
        /// <summary>
        /// 天线胶形状、尺寸
        /// 上宽（mm）2.0±1.0
        /// </summary>
        [ObservableProperty]
        private double? _antennaAdhesiveSpec_TopWidth = 0.0;
        /// <summary>
        /// 天线胶形状、尺寸
        /// 下宽（mm）2.0±1.0
        /// </summary>
        [ObservableProperty]
        private double?  _antennaAdhesiveSpec_BottomWidth = 0.0  ;
        /// <summary>
        /// 天线胶形状、尺寸
        /// 贯通（mm）2.0±1.0
        /// </summary>
        [ObservableProperty]
        private string? _antennaAdhesiveSpec_Penetration;

        /// <summary>
        /// 同步状态
        /// </summary> 
        [ObservableProperty]
        private bool? _syncState=false;
        /// <summary>
        /// 最后同步时间
        /// </summary> 
        [ObservableProperty]
        private DateTime? _lastSyncDate = DateTime.Now;
        /// <summary>
        /// 机台编码
        /// </summary>
        [Description("机台编码")]
        [ObservableProperty]
        private string? _eqp;
        /// <summary>
        /// 断面形状
        /// </summary>
        [Description("断面形状")]
        [ObservableProperty]
        private string? _crossSectionShape;

        [ObservableProperty]
        private string? _userId;

        /// <summary>
        /// 面积比例 %
        /// 
        /// </summary>
        [ObservableProperty]
        [Description("面积比例 %")]
        private float? _data8=0.0f;

        /// <summary>
        /// 总宽(mm)  左 标准
        /// </summary>
        [ObservableProperty]
        [Description("总宽(mm)  左 标准")]
        private float? _data9=0.0f;
        /// <summary>
        /// 总宽(mm)  左 实测
        /// </summary>
        [ObservableProperty]
        [Description("总宽(mm)  左 实测")]
        private float? _data13=0.0f;

        /// <summary>
        /// 总宽(mm)  右 标准
        /// </summary>
        [ObservableProperty]
        [Description("总宽(mm)  右 标准")]
        private float? _data10=0.0f;
        /// <summary>
        /// 总宽(mm)  右 实测
        /// </summary>
        [ObservableProperty]
        [Description("总宽(mm)  右 实测")]
        private float? _data14=0.0f;

        /// <summary>
        /// 总宽(mm)    标准
        /// SemiSteelTreadScanReport.TotalWidth_Stable
        /// </summary>
        [ObservableProperty]
        [Description("总宽(mm)  标准")]
        private float? _data11=0.0f;
        /// <summary>
        /// 总宽(mm)    实测
        /// </summary>
        [ObservableProperty]
        [Description("总宽(mm)  实测")]
        private float? _data15=0.0f;
        /// <summary>
        /// 左右宽度差
        /// </summary>
        [ObservableProperty]
        [Description("左右宽度差")]
        private float? _data18=0.0f;

        /// <summary>
        /// 肩厚（mm）  左 标准
        /// </summary>
        [ObservableProperty]
        [Description("肩厚（mm）左标准")]
        private float? _data19 = 0.0f;
        /// <summary>
        /// 肩厚（mm）  左 实测
        /// </summary>
        [ObservableProperty]
        [Description("肩厚（mm）左实测")]
        private float? _data22 = 0.0f;

        /// <summary>
        /// 肩厚（mm）  右 标准
        /// </summary>
        [ObservableProperty]
        [Description("肩厚（mm）右标准")]
        private float? _data20 = 0.0f;
        /// <summary>
        /// 肩厚（mm）  右 实测
        /// </summary>
        [ObservableProperty]
        [Description("肩厚（mm）右实测")]
        private float? _data23 = 0.0f;

        /// <summary>
        /// 左右肩厚差
        /// </summary>
        [ObservableProperty]
        [Description("左右肩厚差")]
        private float? _data24 = 0.0f;

        //冠宽(mm)
        /// <summary>
        /// 冠宽(mm)  左 标准
        /// </summary>
        [ObservableProperty]
        [Description("冠宽(mm) 左标准")]
        private float? _data25 = 0.0f;
        /// <summary>
        /// 冠宽(mm)  左 实测
        /// </summary>
        [ObservableProperty]
        [Description("冠宽(mm) 左实测")]
        private float? _data29 = 0.0f;
        /// <summary>
        /// 冠宽(mm)  右 标准
        /// </summary>
        [ObservableProperty]
        [Description("冠宽(mm) 右标准")]
        private float? _data26 = 0.0f;
        /// <summary>
        /// 冠宽(mm)  右 实测
        /// </summary>
        [ObservableProperty]
        [Description("冠宽(mm) 右实测")]
        private float? _data30 = 0.0f;

        /// <summary>
        /// 冠宽(mm)    标准
        /// </summary>
        [ObservableProperty]
        [Description("冠宽(mm) 标准")]
        private float? _data27 = 0.0f;
        /// <summary>
        /// 冠宽(mm)     实测
        /// </summary>
        [ObservableProperty]
        [Description("冠宽(mm) 实测")]
        private float? _data31 = 0.0f;

        /// <summary>
        /// 左右冠宽差    实测
        /// </summary>
        [ObservableProperty]
        [Description("左右冠宽差实测")]
        private float? _data32  =0.0f;

        //冠厚(mm)
        /// <summary>
        /// 冠厚(mm)    标准
        /// </summary>
        [ObservableProperty]
        [Description("冠厚(mm) 标准")]
        private float? _data33 = 0.0f;
        /// <summary>
        /// 冠厚    实测
        /// </summary>
        [ObservableProperty]
        [Description("冠厚实测")]
        private float? _data34 = 0.0f;

        /// <summary>
        /// 断面形状
        /// </summary>
        [ObservableProperty]
        [Description("断面形状")]
        private string?  _checkPoint36 = "True";

        /// <summary>
        /// 胎翼宽度(mm)  左  实测
        /// </summary>
        [ObservableProperty]
        [Description("胎翼宽度(mm)  左实测")]
        private float? _data40 = 0.0f;
        /// <summary>
        /// 胎翼宽度(mm)  右  实测
        /// </summary>
        [ObservableProperty]
        [Description("胎翼宽度(mm)  右实测")]
        private float? _data41 = 0.0f;
        /// <summary>
        /// 胎翼宽度(mm)  左右宽度差  实测
        /// </summary>
        [ObservableProperty]
        [Description("胎翼宽度(mm) 左右宽度差实测")]
        private float? _data42 = 0.0f;


        /// <summary>
        /// 边缘端点厚度(mm)  左  实测
        /// </summary>
        [ObservableProperty]
        [Description("边缘端点厚度(mm) 左实测")]
        private float? _data45 = 0.0f;
        /// <summary>
        /// 边缘端点厚度(mm)  右  实测
        /// </summary>
        [ObservableProperty]
        [Description("边缘端点厚度(mm) 右实测")]
        private float? _data46 = 0.0f;

        /// <summary>
        /// 天线胶形状、尺寸  天线胶上端宽度(mm)  实测
        /// </summary>
        [ObservableProperty]
        [Description("天线胶形状、尺寸  天线胶上端宽度(mm)  实测")]
        private float? _data50 = 0.0f;
        /// <summary>
        /// 天线胶形状、尺寸  天线胶下端宽度(mm)  实测
        /// </summary>
        [ObservableProperty]
        [Description("天线胶形状、尺寸  天线胶下端宽度(mm)  实测")]
        private float? _data51 = 0.0f;

        /// <summary>
        /// 天线胶形状、尺寸 天线胶贯通  实测
        /// </summary>
        [ObservableProperty]
        [Description("天线胶形状、尺寸 天线胶贯通 实测")]
        private string? _checkPoint52 = "NULL";

        /// <summary>
        /// 其它点厚度(mm) 标准
        /// </summary>
        [ObservableProperty]
        [Description("其它点厚度(mm)标准")]
        private string? _checkPoint53 = "True";
        /// <summary>
        /// 其它点厚度(mm) 实测
        /// </summary>
        [ObservableProperty]
        [Description("其它点厚度(mm) 实测")]
        private string? _checkPoint54 = "True";

        /// <summary>
        /// 判定
        /// </summary>
        [ObservableProperty]
        [Description("判定")]
        private string? _passStatus = "True";

        /// <summary>
        /// MAX基部胶厚度  标准
        /// </summary>
        [ObservableProperty]
        private float? _manuData30D = 0.0f;
        /// <summary>
        /// MAX基部胶厚度  公差
        /// </summary>
        [ObservableProperty]
        private float? _manuData30E = 0.0f;
        /// <summary>
        /// MAX基部胶厚度  实测
        /// </summary>
        [ObservableProperty]
        private float? _manuData30F = 0.0f;

        /// <summary>
        /// MIN基部胶厚度  标准
        /// </summary>
        [ObservableProperty]
        private float? _manuData31D = 0.0f;
        /// <summary>
        /// MIN基部胶厚度  公差
        /// </summary>
        [ObservableProperty]
        private float? _manuData31E = 0.0f;
        /// <summary>
        /// MIN基部胶厚度  实测
        /// </summary>
        [ObservableProperty]
        private float? _manuData31F = 0.0f;

        /// <summary>
        /// 基部胶厚度差  标准
        /// </summary>
        [ObservableProperty]
        private float? _manuData32D = 0.0f;
        /// <summary>
        /// 基部胶厚度差  公差
        /// </summary>
        [ObservableProperty]
        private float? _manuData32E = 0.0f;
        /// <summary>
        /// 基部胶厚度差  实测
        /// </summary>
        [ObservableProperty]
        private float? _manuData32F = 0.0f;

        /// <summary>
        /// 胎面基部胶最小厚度  标准
        /// </summary>
        [ObservableProperty]
        private float? _manuData33D = 0.0f;
        /// <summary>
        /// 胎面基部胶最小厚度  公差
        /// </summary>
        [ObservableProperty]
        private float? _manuData33E = 0.0f;
        /// <summary>
        /// 胎面基部胶最小厚度  实测
        /// </summary>
        [ObservableProperty]
        private float? _manuData33F = 0.0f;

        /// <summary>
        /// TUC差级ⅠA-BⅠ(mm)  实测
        /// </summary>
        [ObservableProperty]
        private float? _manuData34F = 0.0f  ;

        /// <summary>
        /// 备注
        /// </summary>
        [ObservableProperty]
        private string? _remark;

        public override YB_PROCESS_STEP ToYB_PROCESS_STEP(DataFile dataFile)
        {
            //var dataFile = DataFile.FromSpecVal(this.SpecVal);
            var processStep = new YB_PROCESS_STEP
            {
                // 映射 SemiSteelTreadScanReport 的字段到 RECORD16 至 RECORD43 
                PLAN_ID = this.PlanId,
                PART_NUMBER = this.SpecName,
                RECORD122 = this.Data8?.ToString("F1"),// this.TotalArea.ToString("F1"),
                RECORD123 = this.MeasureArea?.ToString("F1"),
                RECORD124 = this.TotalLeftArea?.ToString("F1"),
                RECORD125 = this.MeasureLeftArea?.ToString("F1"),
                RECORD126 = this.TotalRightArea?.ToString("F1"),
                RECORD127 = this.MeasureRightArea?.ToString("F1"),
                //总宽设定值
                RECORD128 = this.TotalWidth_Stable?.ToString("F1"),
                RECORD129 = this.TotalWidth_Scan?.ToString("F1"),
                //左侧宽设定值
                RECORD130 = (this.TotalWidth_Stable / 2)?.ToString("F1"),
                RECORD131 = Math.Abs(dataFile.XReference - dataFile.MeasureKeys.FirstOrDefault().Coordinate).ToString("F1"),
                //右侧宽设定值
                RECORD132 = (this.TotalWidth_Stable / 2).Value.ToString("F1"),
                RECORD133 = Math.Abs(dataFile.XReference - dataFile.MeasureKeys.LastOrDefault().Coordinate).ToString("F1"),
                //冠宽设定值
                RECORD134 = this.CrownWidth_Stable?.ToString("F1"),
                RECORD135 = this.CrownWidth_Scan?.ToString("F1"),
                //左冠宽设定值
                RECORD136 = Math.Abs((dataFile.StableKeys.ElementAt(dataFile.StableKeys.Count() - 2).Coordinate - dataFile.StableKeys[1].Coordinate) / 2).ToString("F1"),
                RECORD137 = Math.Abs(dataFile.XReference - dataFile.MeasureKeys[1].Coordinate).ToString("F1"),
                //右冠宽设定值
                RECORD138 = Math.Abs((dataFile.StableKeys.ElementAt(dataFile.StableKeys.Count() - 2).Coordinate - dataFile.StableKeys[1].Coordinate) / 2).ToString("F1"),
                RECORD139 = Math.Abs(dataFile.MeasureKeys.ElementAt(dataFile.MeasureKeys.Count() - 2).Coordinate - dataFile.XReference).ToString("F1"),
                //左肩厚设定值
                RECORD140 = dataFile.StableKeys[1].Value.ToString("F1"),
                RECORD141 = dataFile.MeasureKeys[1].Value.ToString("F1"),
                //右肩厚设定值
                RECORD142 = dataFile.StableKeys.ElementAt(dataFile.StableKeys.Count() - 2).Value.ToString("F1"),
                RECORD143 = dataFile.MeasureKeys.ElementAt(dataFile.MeasureKeys.Count() - 2).Value.ToString("F1"),
                //冠厚设定值
                RECORD144 = this.CrownThickness_Stable?.ToString("F1"),
                //RECORD145 = (this.CrownThickness_Scan + this.CompensationCoefficient)?.ToString("F1"),//+补偿值
                RECORD145 = (this.CrownThickness_Scan)?.ToString("F1"),//+补偿值
                //左胎翼端点厚度设定值
                RECORD146 = dataFile.StableKeys[0].Value.ToString("F1"),
                RECORD147 = dataFile.MeasureKeys[0].Value.ToString("F1"),
                //右胎翼端点厚度设定值
                RECORD148 = dataFile.StableKeys.LastOrDefault().Value.ToString("F1"),
                RECORD149 = dataFile.MeasureKeys.LastOrDefault().Value.ToString("F1"),
                //左胎翼宽度设定值
                RECORD150 = Math.Abs(dataFile.StableKeys[1].Coordinate - dataFile.StableKeys[0].Coordinate).ToString("F1"),
                RECORD151 = Math.Abs(dataFile.MeasureKeys[1].Coordinate - dataFile.MeasureKeys[0].Coordinate).ToString("F1"),
                //右胎翼宽度设定值
                RECORD152 = Math.Abs(dataFile.StableKeys.ElementAt(dataFile.StableKeys.Count() - 2).Coordinate - dataFile.StableKeys.LastOrDefault().Coordinate).ToString("F1"),
                RECORD153 = Math.Abs(dataFile.MeasureKeys.ElementAt(dataFile.MeasureKeys.Count() - 2).Coordinate - dataFile.MeasureKeys.LastOrDefault().Coordinate).ToString("F1"),
                //检测结果
                //RECORD154 = this.SpecVal.TestResult,
                //问题点RECORD155
                //RECORD156 = dataFile.FileInertvaWidth.ToString("F1"),

                //检验员
                RECORD159 = this.UserId,
                //面积比
                RECORD160 = this.AreaPercent.ToString("F1"),
                //总宽对称性
                RECORD161 = this.TotalWidth_Symmetry?.ToString("F1"),
                //冠宽对称性
                RECORD162 = this.CrownWidth_Symmetry?.ToString("F1"),
                //断面形状
                RECORD164 = this.CheckPoint36, //this.CrossSectionShape,
                //RECORD163
                RECORD163 = this.ShoulderThickness_Symmetry?.ToString("F1"),
                //胎翼宽度对称性
                RECORD165 = this.BeadWingWidth_Symmetry?.ToString("F1"),
                //天线胶上宽
                RECORD166 = this.Data50?.ToString("F1"), //this.AntennaAdhesiveSpec_TopWidth.ToString("F1"),
                //天线胶下宽
                RECORD167 = this.Data51?.ToString("F1"),//this.AntennaAdhesiveSpec_BottomWidth.ToString("F1"),
                //天线胶贯通
                RECORD168 = this.CheckPoint52, //this.AntennaAdhesiveSpec_Penetration,
                //其他点厚度标准
                //RECORD177 = this.OthoerPointsThickness_Stable,
                //其他点厚度扫描
                //RECORD178 = this.OthoerPointsThickness_Scan,

                EQP = this.Eqp,

                RECORD154 = this.ManuData30D?.ToString("F1"),  //MAX基部胶厚度标准
                RECORD155 = this.ManuData30E?.ToString("F1"),  //  MAX基部胶厚度公差
                RECORD156 = this.ManuData31D?.ToString("F1"),  //   MIN基部胶厚度标准
                RECORD157 = this.ManuData31E?.ToString("F1"),  //   MIN基部胶厚度公差

                RECORD158 = this.ManuData34F?.ToString("F1"),  //  TUC差级实际值

                RECORD177 = this.CheckPoint53,//  其他点厚度标准
                RECORD178 = this.CheckPoint54,//  其他点厚度扫描

                RECORD169 = this.Shift,//  班次
                RECORD170 = this.ManuData30F?.ToString("F1"),  //   MAX基部胶厚度实际
                RECORD171 = this.ManuData31F?.ToString("F1"),  //   MIN基部胶厚度实际
                RECORD172 = this.ManuData32D?.ToString("F1"),  //   基部胶厚度差标准
                RECORD173 = this.ManuData32E?.ToString("F1"),  //   基部胶厚度差公差
                RECORD174 = this.ManuData32F?.ToString("F1"),  //   基部胶厚度差实际

                RECORD179 = this.ManuData33D?.ToString("F1"),  //  胎面基部胶最小厚度标准
                RECORD180 = this.ManuData33E?.ToString("F1"),  //  胎面基部胶最小厚度公差
                RECORD181 = this.ManuData33F?.ToString("F1"),  //  胎面基部胶最小厚度实际

                RECORD175=  this.CompensationCoefficient?.ToString("F1"),//补偿系数
                RECORD225 = this.PassStatus,    //  判定结果
                RECORD226 = this.Remark,        //  备注
                RECORD227 = this.SpecNameInfact,//  实际规格

            };
            this.UpdateProcessStep(processStep, dataFile);
            return processStep;
        }
    }
}
